package nz.co.doherty.gwtpbreadcrumbs.client.ui.customers;

import nz.co.doherty.gwtpbreadcrumbs.client.i8n.ClientConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.philbeaudoin.gwtp.mvp.client.ViewImpl;


public class CustomerCreateViewImpl extends ViewImpl implements CustomerCreateView {

	interface Binder extends UiBinder<Widget, CustomerCreateViewImpl> {
	}

	private static Binder binder = GWT
			.create(Binder.class);

	Widget widget;
	
	@UiField
	TextBox firstName;

	@UiField
	TextBox lastName;

	@UiField
	Button create;

	private Provider<Presenter> presenterProvider;
		
	@Inject
	public CustomerCreateViewImpl(ClientConstants constants, Provider<CustomerCreateView.Presenter> presenterProvider) {
		widget = binder.createAndBindUi(this);
		this.presenterProvider = presenterProvider;
	}

	@Override
	public Widget asWidget() {
		return widget;
	}
	
	@UiHandler("create") 
	public void onCreate(ClickEvent event) {
		presenterProvider.get().onCreate();
	}

	@Override
	public void reset() {
		this.firstName.setText("");		
		this.lastName.setText("");
	}

	@Override
	public String getFirstName() {
		return this.firstName.getText();
	}

	@Override
	public String getLastName() {
		return this.lastName.getText();
	}

	
}
